
package cz.muni.fi.pa165.carpark.TO;

import java.util.Collections;
import java.util.Set;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.GenericConverter;

/**
 *
 * @author xmarton1
 */
public class TOConverter implements GenericConverter,InitializingBean{
    
    private Mapper mapper;

    @Override
    public Set<ConvertiblePair> getConvertibleTypes() {
        return Collections.singleton(new ConvertiblePair(Object.class, Object.class));
    }

    @Override
    public Object convert(Object o, TypeDescriptor td, TypeDescriptor td1) {
        return mapper.map(o, td1.getType());
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        if(mapper == null)
        {
            mapper = new DozerBeanMapper();
        }
    }
    
    public void setMapper(final Mapper mapper)
    {
        this.mapper = mapper;
    }
    
    public Mapper getMapper()
    {
        return this.mapper;
    }

}
